<script>

import * as echarts from 'echarts';
export default {
  name: 'VisualizationTwo',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {

      let index = [];
      let data1 = [];
      let data2 = [];
      let data3 = [];
      let data4 = [];
      let data5 = [];
      for (let i = 1; i < 36; i++) {
        index.push(i);
      }

      this.$axios.get('/api/vis/data2', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data = [];
          for (let i = 0; i < res.data.data.length; i++) {
            data.push(
                res.data.data[i].param2
            )
          }
          data.push(0);
          data.push(0);
          data.push(0);
          data.push(0);
          data.push(0);
          data1 = data;
        }
      }).catch(error =>{
        this.open4(error);
      });
      this.$axios.get('/api/vis/data3', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data = [];
          data.push(0);
          for (let i = 0; i < res.data.data.length; i++) {
            data.push(
                res.data.data[i].param2
            )
          }
          data.push(0);
          data.push(0);
          data.push(0);
          data2 = data;
        }
      }).catch(error =>{
        this.open4(error);
      });
      this.$axios.get('/api/vis/data4', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data = [];
          data.push(0);
          data.push(0);
          for (let i = 0; i < res.data.data.length; i++) {
            data.push(
                res.data.data[i].param2
            )
          }
          data.push(0);
          data.push(0);
          data3 = data;
        }
      }).catch(error =>{
        this.open4(error);
      });
      this.$axios.get('/api/vis/data5', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data = [];
          data.push(0);
          data.push(0);
          data.push(0);
          for (let i = 0; i < res.data.data.length; i++) {
            if(i === 0) {
              data.push(
                  res.data.data[i].param2
              )
              data.push(0)
            }
            data.push(
                res.data.data[i].param2
            )
          }
          data.push(0);
          data4 = data;
        }
      }).catch(error =>{
        this.open4(error);
      });
      this.$axios.get('/api/vis/data6', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data = [];
          data.push(0);
          data.push(0);
          data.push(0);
          data.push(0);
          data.push(0);
          data.push(0);
          data.push(0);
          for (let i = 0; i < res.data.data.length; i++) {
            data.push(
                res.data.data[i].param2
            )
          }
          data5 = data;
          this.init(index, data1, data2, data3, data4, data5);
        }
      }).catch(error =>{
        this.open4(error);
      });
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(index, data1, data2, data3, data4, data5) {
      var chartDom = document.getElementById('main2');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '超级大乐透红球出现次数'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['红球1', '红球2', '红球3', '红球4', '红球5']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: index
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '红球1',
            type: 'line',
            stack: 'Total',
            data: data1
          },
          {
            name: '红球2',
            type: 'line',
            stack: 'Total',
            data: data2
          },
          {
            name: '红球3',
            type: 'line',
            stack: 'Total',
            data: data3
          },
          {
            name: '红球4',
            type: 'line',
            stack: 'Total',
            data: data4
          },
          {
            name: '红球5',
            type: 'line',
            stack: 'Total',
            data: data5
          }
        ]
      };

      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main2"></div>
</template>

<style scoped>
#main2 {
  width: 100%;
  height: 100%;
}
</style>